/**
 * 
 */
package com.pengtu.entity.detect.grade;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;


import com.pengtu.entity.IdEntity;
import com.pengtu.entity.project.SignUpContract;
import com.pengtu.utils.MathsUtils;

/**
 * @author Administrator 合同段工程质量鉴定
 */
@Entity
@Table(name="T_Q_GRADE_SIGNPROJQUACHECK")
public class SignProjQuaCheck extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String projId;
	private SignUpContract signContruct;
	private Double signProjPrice;
	private String quaLevel;
	private Double checkPoint;
	private Double innerSheetPoint;
	private Double appraisalPoint;
	private String remark;
	private List<UnitProj> unitProjList = new ArrayList<UnitProj>();

	@Column(name="PROJID")
	public String getProjId() {
		return projId;
	}

	public void setProjId(String projId) {
		this.projId = projId;
	}

	@ManyToOne
	@JoinColumn(name="SIGNCONTRUCTID")
	public SignUpContract getSignContruct() {
		return signContruct;
	}

	public void setSignContruct(SignUpContract signContruct) {
		this.signContruct = signContruct;
	}
	
	
	
	@Column(name="PRICE")
	public Double getSignProjPrice() {
		return signProjPrice;
	}

	public void setSignProjPrice(Double signProjPrice) {
		this.signProjPrice = signProjPrice;
	}

	@Column(name="QUALEVEL")
	public String getQuaLevel() {
		return quaLevel;
	}

	public void setQuaLevel(String quaLevel) {
		this.quaLevel = quaLevel;
	}
	
	@Column(name="CHECKPOINT")
	public Double getCheckPoint() {
		return checkPoint;
	}

	public void setCheckPoint(Double checkPoint) {
		this.checkPoint = checkPoint;
	}
	
	@Column(name="INNERSHEETPOINT")
	public Double getInnerSheetPoint() {
		return innerSheetPoint;
	}

	public void setInnerSheetPoint(Double innerSheetPoint) {
		this.innerSheetPoint = innerSheetPoint;
	}
	
	@Column(name="APPRAISALPOINT")
	public Double getAppraisalPoint() {
		return appraisalPoint;
	}

	public void setAppraisalPoint(Double appraisalPoint) {
		this.appraisalPoint = appraisalPoint;
	}
	
	@Column(name="REMARK")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	
	@OneToMany
	@JoinColumn(name="SIGNPROJID")
	public List<UnitProj> getUnitProjList() {
		return unitProjList;
	}

	public void setUnitProjList(List<UnitProj> unitProjList) {
		this.unitProjList = unitProjList;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	//获取优良单位工程数
	@Transient
	public Integer getFineNum(){
		List<UnitProj> finePro = new ArrayList<UnitProj>();
		for (int i = 0; i < this.getUnitProjList().size(); i++) {
			if("优良".equals(this.getUnitProjList().get(i).getQuaLevel())){
				finePro.add(this.getUnitProjList().get(i));
			}
			if("不合格".equals(this.getUnitProjList().get(i).getQuaLevel())){
				return 0;
			}
		}
		return finePro.size();
	}
	
	//获得单位工程优良率
	@Transient
	public Double  getFineProbability(){
		return MathsUtils.div("2",this.getFineNum(),this.getUnitProjList().size());
	} 
	
	

	//获取优良单位工程数
	@Transient
	public Integer getUnitQualifiedNum(){
		int total = 0;
		for (int i = 0; i < this.getUnitProjList().size(); i++) {
			if("不合格".equals(this.getUnitProjList().get(i).getQuaLevel())){
				total++;
			}
		}
		return MathsUtils.sub(this.getUnitProjList().size(),total);
	}
	
	//获得单位工程合格率
	@Transient
	public Double  getUnitQualifiedPro(){
		return MathsUtils.div("2",this.getUnitQualifiedNum(),this.getUnitProjList().size());
	} 
	
}
